package com.lq.service.impl;

import com.lq.mapper.DocumentMapper;
import com.lq.pojo.Document;
import com.lq.service.DocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DocumentServiceImpl implements DocumentService {

    @Autowired
    private DocumentMapper documentMapper;

    @Override
    public void saveFile(String url, Integer userId) {
        //文件全名:文件名+扩展名
        String fullName =  url.substring(url.lastIndexOf("\\"),url.length()).substring(1);

        //文件名
        String fileName = fullName.substring(0,fullName.lastIndexOf("."));

        //扩展名
        String extension =fullName.substring(fullName.lastIndexOf("."),fullName.length()).substring(1);

        documentMapper.saveFile(fileName,url,extension,userId);

    }

    @Override
    public List<Document> getAllDocumentByUserId(Integer offset, Integer limit, Integer userId) {
        return documentMapper.getAllDocumentByUserId(offset, limit, userId);
    }

    @Override
    public boolean deleteDocumentById(Integer documentId) {
        return documentMapper.deleteDocumentById(documentId);
    }

    @Override
    public Integer getNumsOfDocumentByUserId(Integer userId) {
        return documentMapper.getNumsOfDocumentByUserId(userId);
    }

    @Override
    public String getDocumentPathByDocId(Integer documentId) {
        return documentMapper.getDocumentPathByDocId(documentId);
    }
}
